# coding=utf-8
from flask import session

from src.db.dbhelper import query_sql_by_pandas


def login_check(uname, upwd):
    sql = f"SELECT count(*) ct FROM  sys_user where uname = '{uname}' and upwd = '{upwd}' and is_del = 0 "
    df = query_sql_by_pandas(sql)
    ct = df.iloc[0]["ct"]
    if ct <= 0:
        return {
            "code": 500,
            "msg": "用户名或者密码错误"
        }
    else:
        session.setdefault("username", uname)
        return {
            "code": 200,
            "msg": "登录成功"
        }
